﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using LoanCalculator.BusinessLogic.Payments;

namespace LoanCalculator.WcfService
{
    public class LCService : ILCService
    {
        public double CalculateMonthlyPayment(
            double loanAmount, double annualInterestRate,
            double months, double downPayment,
            double propertyTax, double propertyInsurance)
        {
            PaymentService ps = new PaymentService();
            return ps.CalculateMonthlyPayment(loanAmount, annualInterestRate, months, downPayment, propertyTax, propertyInsurance);
        }

        public IList<Payments> CalculateAmortization(
            double loanAmount, double annualInterestRate,
            double months, double downPayment,
            double propertyTax, double propertyInsurance)
        {
            PaymentService ps = new PaymentService();
            var results = ps.CalculateAmortization(loanAmount, annualInterestRate, months, downPayment, propertyTax, propertyInsurance);

            IList<Payments> payments = new List<Payments>();

            foreach (var payment in results)
            {
                Payments p = new Payments { 
                    Month = payment.Month, 
                    Interest = payment.Interest, 
                    Payment = payment.Payment, 
                    Reduction = payment.Reduction, 
                    Principle = payment.Principle };
                payments.Add(p);
            }

            return payments;
        }
    }
}
